package com.xmall.pethouse_api.mapper;

import com.xmall.pethouse_api.pojo.entity.UserAddress;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Options;
import java.util.List;

@Mapper
public interface AddressMapper {
    @Select("SELECT * FROM user_addresses WHERE user_id = #{userId}")
    List<UserAddress> findByUserId(Long userId);

    @Insert("INSERT INTO user_addresses (user_id, receiver_name, receiver_phone, province, city, district, detail_address, is_default, created_at, updated_at) " +
            "VALUES (#{userId}, #{receiverName}, #{receiverPhone}, #{province}, #{city}, #{district}, #{detailAddress}, #{isDefault}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(UserAddress address);

    @Delete("DELETE FROM user_addresses WHERE id = #{id}")
    void delete(Long id);
} 